package org.kl.bf.service;

import org.kl.bf.entity.easyui.Json;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springside.modules.mapper.JsonMapper;

/**
 * 打印业务日志，格式为:
 * 
 * 日期,实体类型,操作类型 ,操作用户,json格式的扩展字段
 * 
 * @Author hqm
 * @CreateTime 2014年4月26日 上午11:43:58
 */
@Component
public class ExcelImportLogger {
	private static final String BUSINESS_LOGGER_NAME = "excelImport";

	public enum LoggerAction {
		FORMET_CHECKS("格式检查");
		private String name;

		private LoggerAction(String name) {
			this.name = name;
		}

		public String getActionName() {
			return this.name;
		}
	}

	private Logger businessLogger = LoggerFactory.getLogger(BUSINESS_LOGGER_NAME);
	private JsonMapper jsonMapper = new JsonMapper();

	public void log(String entity, String action, String user, Json data) {
		String json = (data != null ? jsonMapper.toJson(data) : "{}");
		businessLogger.info("{},{},{},{}", entity, action, user, json);
	}
}
